package com.zhehekeji.opsys.api.dao;

import org.bson.Document;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

/**
 * @ClassName MongoDaoImpl
 * @Description TODO
 * @author chenweiliu chenwei.liu@163.com
 * @date 2015-5-28   下午3:15:34
 */
public class MongoDaoImpl {
	
	private MongoDatabase mongoDatabase;
	private MongoClient mongoClient;
	
	public MongoDaoImpl(MongoClient mongoClient,String databaseName){
		this.mongoClient = mongoClient;
		mongoDatabase = this.mongoClient.getDatabase(databaseName);
	}
	/**
	 * 
	* @Title: getMongoDatabase 
	* @Description: 默认数据库
	* @return 
	* @return MongoDatabase 
	* @throws
	 */
	public MongoDatabase getMongoDatabase() {
		return mongoDatabase;
	}
	/**
	 * 
	* @Title: getMongoDatabase 
	* @Description: 获取指定的数据库
	* @param databaseName 数据库名称
	* @return 
	* @return MongoDatabase 
	* @throws
	 */
	public MongoDatabase getMongoDatabase(String databaseName) {
		return mongoClient.getDatabase(databaseName);
	}
	
	/**
	 * 
	* @Title: getCollection 
	* @Description: 获取集合
	* @param collectionName 结合名称
	* @return 
	* @return MongoCollection<Document> 
	* @throws
	 */
	public  MongoCollection<Document> getCollection(String collectionName){
		return mongoDatabase.getCollection(collectionName);
	}

}
